package com.yanfan.njLighting.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.njLighting.domain.NjLightingDeviceStatus;
import com.yanfan.njLighting.service.INjLightingDeviceStatusService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 开关状态列Controller
 *
 * @author genluo
 * @date 2024-10-30
 */
@Api(tags = "开关状态列")
@RestController
@RequestMapping("/njLighting/lightinStatus")
public class NjLightingDeviceStatusController extends BaseController {
    @Autowired
    private INjLightingDeviceStatusService njLightingDeviceStatusService;

    /**
     * 查询开关状态列列表
     */
    @ApiOperation("开关状态列分页列表")
    @PreAuthorize("@ss.hasPermi('njLighting:lightinStatus:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjLightingDeviceStatus njLightingDeviceStatus) {
        startPage();
        List<NjLightingDeviceStatus> list = njLightingDeviceStatusService.queryPageList(njLightingDeviceStatus);
        return getDataTable(list);
    }

    /**
     * 导出开关状态列列表
     */
    @ApiOperation("导出开关状态列列表")
    @PreAuthorize("@ss.hasPermi('njLighting:lightinStatus:export')")
    @Log(title = "开关状态列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjLightingDeviceStatus njLightingDeviceStatus) {
        List<NjLightingDeviceStatus> list = njLightingDeviceStatusService.queryPageList(njLightingDeviceStatus);
        ExcelUtil<NjLightingDeviceStatus> util = new ExcelUtil<NjLightingDeviceStatus>(NjLightingDeviceStatus.class);
        util.exportExcel(response, list, "开关状态列数据");
    }

    /**
     * 获取开关状态列详细信息
     */
    @ApiOperation("获取开关状态列详细信息")
    @PreAuthorize("@ss.hasPermi('njLighting:lightinStatus:query')")
    @GetMapping(value = "/{deviceOffset}")
    public AjaxResult getInfo(@PathVariable("deviceOffset") String deviceOffset) {
        NjLightingDeviceStatus one = njLightingDeviceStatusService.getOne(new LambdaQueryWrapper<NjLightingDeviceStatus>()
                .eq(NjLightingDeviceStatus::getDeviceOffset, deviceOffset));
        return success(one);
    }

    /**
     * 新增开关状态列
     */
    @ApiOperation("新增开关状态列")
    @PreAuthorize("@ss.hasPermi('njLighting:lightinStatus:add')")
    @Log(title = "开关状态列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjLightingDeviceStatus njLightingDeviceStatus) {
        return toAjax(njLightingDeviceStatusService.save(njLightingDeviceStatus));
    }

    /**
     * 修改开关状态列
     */
    @ApiOperation("修改开关状态列")
    @PreAuthorize("@ss.hasPermi('njLighting:lightinStatus:edit')")
    @Log(title = "开关状态列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjLightingDeviceStatus njLightingDeviceStatus) {
        njLightingDeviceStatus.setUpdateTime(DateUtils.getTime());
        return toAjax(njLightingDeviceStatusService.updateById(njLightingDeviceStatus));
    }

    /**
     * 删除开关状态列
     */
    @ApiOperation("删除开关状态列")
    @PreAuthorize("@ss.hasPermi('njLighting:lightinStatus:remove')")
    @Log(title = "开关状态列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(njLightingDeviceStatusService.removeBatchByIds(Arrays.asList(ids)));
    }
    @ApiOperation("开关控制")
    @PutMapping("/updateByStatus")
    public AjaxResult updateByStatus(@RequestBody NjLightingDeviceStatus lightingDeviceStatus){
        AjaxResult ajaxResult = njLightingDeviceStatusService.updateByStatus(lightingDeviceStatus);
        return  ajaxResult;

    }
}
